package com.rmb.controller;


import com.rmb.service.LogAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName LogAddress
 * @Description 登录日志
 * @Author lvshook
 * @Date 2021/1/20 10:55
 * @Version 1.0
 **/
@RestController
@RequestMapping("/rmb/address")
public class LogAddressController {

    @Autowired
    private LogAddressService logAddressService;

    /**
     * 查询用户近一次登陆时间
     * @param uid
     * @return
     */
    @GetMapping("/findone")
    public String findone(@RequestParam("uid") Long uid){
        System.out.println(uid);
        Date findone = logAddressService.findone(uid);
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String format1 = format.format(findone);
        return format1;
    }

    /**
     * 查询本地ip 以及IP所在地区
     * @param request
     * @return
     */
    @GetMapping("/getip")
    public Map getip(HttpServletRequest request){

        return logAddressService.getip(request);
    }

    /**
     * 登录记录表
     * @param uid
     * @return
     */
    @GetMapping("/logall")
    public List logAll(@RequestParam("uid") Long uid){
        return logAddressService.logAll(uid);
    }

}
